package com.ymttest.database.sqlwapper.anlihui;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.anlihui.Settlement;

public class SettlementWrapper {
	
	SqlManager manager;

    public SettlementWrapper() {
        manager = new SqlManager("anlihui");
    }
    
    @SuppressWarnings("unchecked")
	public Settlement selectByPrimaryKey(String id) {
    	
    	Settlement settlement = new Settlement();
    	List<Settlement> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.anlihui.SettlementMapper.selectByPrimaryKey",
                        id);
        manager.commit();
        
		if (result.size() > 0) {
			settlement = result.get(0);
		}
		
        return settlement;
    }
    
    @SuppressWarnings("unchecked")
	public List<Settlement> selectByOrderId(long orderId) {
    	
    	List<Settlement> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.anlihui.SettlementMapper.selectByOrderId",
                        orderId);
        manager.commit();
        
        return result;
    }
    
    @SuppressWarnings("unchecked")
	public List<Settlement> selectByOrderIdAndUserId(long orderId, long userId) {
    	
    	HashMap<String, Object> map = new HashMap<>();
    	
    	map.put("orderId", orderId);
    	map.put("userId", userId);
    	
    	List<Settlement> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.anlihui.SettlementMapper.selectByOrderIdAndUserId",
                        map);
        manager.commit();
        
        return result;
    }
    
    @SuppressWarnings("unchecked")
	public Settlement selectByOrderIdAndBizNoAndType(long orderId, String bizNo, int type) {
    	
    	HashMap<String, Object> map = new HashMap<>();
    	
    	Settlement settlement = new Settlement();
    	
    	map.put("orderId", orderId);
    	map.put("bizNo", bizNo);
    	map.put("type", type);
    	
    	List<Settlement> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.anlihui.SettlementMapper.selectByOrderIdAndBizNoAndType",
                        map);
        manager.commit();
        
        if (result.size() > 0) {
			settlement = result.get(0);
		}
        
        return settlement;
    }
    
	public int updateExpectSettlementTimeByOrderId(Date expectSettlementTime, long orderId) {
    	
    	HashMap<String, Object> map = new HashMap<>();
    	
    	map.put("expectSettlementTime", expectSettlementTime);
    	map.put("orderId", orderId);
    	
		int result = manager.update(
				"com.ymttest.database.mapping.anlihui.SettlementMapper.updateExpectSettlementTimeByOrderId",
				map);
        manager.commit();
        
        return result;
    }
    
    public static void main(String[] args) {
    	
    	SettlementWrapper test = new SettlementWrapper();
    	
    	Settlement settlement = test.selectByOrderIdAndUserId(8596948699L, 20238699).get(0);
//    	Settlement settlement = test.selectByOrderIdAndBizNoAndType(7880798699L, "TK07880798699", 30);
    	
    	System.out.println(settlement.getBiz_no());
    }
}
